<?php

require_once "php/util/util.php";

class FreeGeoIPAPIHandler {

    // property declaration
    public $response;

    public function __construct() {
    }

    public function connect() {
        $public_ip = getPublicClientIP();
        $remote_addr = $public_ip == "127.0.0.1" ? "72.204.154.208" : $public_ip;
        $unsigned_url = "http://freegeoip.net/"."json"."/". $remote_addr;
        $ch = curl_init($unsigned_url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        $data = curl_exec($ch); // response
        curl_close($ch);
        $response = json_decode($data);
        $this->response = $response;
    }
}
?>
